package main

import (
	"fmt"
	"sync"
	"time"
)

const birthTime = "2006-01-02 15:04:05"

func main() {
	var wg sync.WaitGroup
	fmt.Println(time.Now().Format(birthTime))
	wg.Add(1)
	go routine1(&wg)
	wg.Add(1)
	go routine2(&wg)
	wg.Add(1)
	go routine3(&wg)
	wg.Wait()
	fmt.Println(time.Now().Format(birthTime))
}

func routine1(wg *sync.WaitGroup) {
	time.Sleep(time.Second)
	wg.Done()
	fmt.Println("routine1 over")
}
func routine2(wg *sync.WaitGroup) {
	<-time.After(2 * time.Second)
	wg.Done()
	fmt.Println("routine2 over")
}
func routine3(wg *sync.WaitGroup) {
	ticker := time.NewTicker(time.Second) //定时器
	for index := 0; index < 3; index++ {
		<-ticker.C
	}
	ticker.Stop()
	wg.Done()
	fmt.Println("routine3 over")
}
